1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.TextBuffer; 26 27 private import core.vararg; 28 private import gdk.Clipboard; 29 private import gdk.ContentProvider; 30 private import gdk.PaintableIF; 31 private import glib.ConstructionException; 32 private import glib.MemorySlice; 33 private import glib.Str; 34 private import glib.c.functions; 35 private import gobject.ObjectG; 36 private import gobject.Signals; 37 private import gobject.c.functions; 38 private import gtk.TextChildAnchor; 39 private import gtk.TextIter; 40 private import gtk.TextMark; 41 private import gtk.TextTag; 42 private import gtk.TextTagTable; 43 private import gtk.c.functions; 44 public import gtk.c.types; 45 private import pango.PgFontDescription; 46 private import pango.PgTabArray; 47 private import std.algorithm; 48 private import std.stdio; 49 50 51 /** 52 * Stores text and attributes for display in a `GtkTextView`. 53 * 54 * You may wish to begin by reading the 55 * [text widget conceptual overview](section-text-widget.html), 56 * which gives an overview of all the objects and data types 57 * related to the text widget and how they work together. 58 * 59 * GtkTextBuffer can support undoing changes to the buffer 60 * content, see [method@Gtk.TextBuffer.set_enable_undo]. 61 */ 62 public class TextBuffer : ObjectG 63 { 64 /** the main Gtk struct */ 65 protected GtkTextBuffer* gtkTextBuffer; 66 67 /** Get the main Gtk struct */ 68 public GtkTextBuffer* getTextBufferStruct(bool transferOwnership = false) 69 { 70 if (transferOwnership) 71 ownedRef = false; 72 return gtkTextBuffer; 73 } 74 75 /** the main Gtk struct as a void* */ 76 protected override void* getStruct() 77 { 78 return cast(void*)gtkTextBuffer; 79 } 80 81 /** 82 * Sets our main struct and passes it to the parent class. 83 */ 84 public this (GtkTextBuffer* gtkTextBuffer, bool ownedRef = false) 85 { 86 this.gtkTextBuffer = gtkTextBuffer; 87 super(cast(GObject*)gtkTextBuffer, ownedRef); 88 } 89 90 /** 91 * Inserts text into buffer at iter, applying the list of tags to 92 * the newly-inserted text. The last tag specified must be NULL to 93 * terminate the list. Equivalent to calling gtk_text_buffer_insert(), 94 * then gtk_text_buffer_apply_tag() on the inserted text; 95 * gtk_text_buffer_insert_with_tags() is just a convenience function. 96 * Params: 97 * iter = an iterator in buffer 98 * text = UTF-8 text 99 * tags = list of tags to apply 100 */ 101 public void insertWithTags(TextIter iter, string text, TextTag[] tags ... ) 102 { 103 int startOffset = iter.getOffset(); 104 105 insert(iter, text); 106 107 if ( tags.length == 0 ) 108 return; 109 110 TextIter start = new TextIter(); 111 getIterAtOffset(start, startOffset); 112 113 foreach( tag; tags ) 114 { 115 applyTag(tag, start, iter); 116 } 117 } 118 119 /** 120 * Same as gtk_text_buffer_insert_with_tags(), but allows you 121 * to pass in tag names instead of tag objects. 122 * Params: 123 * iter = position in buffer 124 * text = UTF-8 text 125 * tags = tag names 126 */ 127 public void insertWithTagsByName(TextIter iter, string text, string[] tags ... ) 128 { 129 int startOffset = iter.getOffset(); 130 131 insert(iter, text); 132 133 if ( tags.length == 0 ) 134 return; 135 136 TextIter start = new TextIter(); 137 getIterAtOffset(start, startOffset); 138 139 foreach( tag; tags ) 140 { 141 applyTagByName(tag, start, iter); 142 } 143 } 144 145 /** 146 * Creates a tag and adds it to the tag table for buffer. Equivalent to 147 * adding a new tag to the buffer's tag table. 148 * 149 * If tagName is null, the tag is anonymous. 150 * 151 * If tagName is non-NULL, a tag called tagName must not already exist 152 * in the tag table for this buffer. 153 * 154 * Params: 155 * tagName = the name for the new tag. 156 * ... = A list of property names and there values. 157 */ 158 TextTag createTag(string tagName, ...) 159 { 160 TextTag tag = new TextTag(gtk_text_buffer_create_tag(gtkTextBuffer, Str.toStringz(tagName), null, null)); 161 162 for (size_t i = 0; i < _arguments.length; i+=2) 163 { 164 //TODO: Add a proper eception type for this. 165 if ( _arguments[i] != typeid(string) ) 166 throw new Exception("TextBuffer.CreateTag: The property name must be a string."); 167 168 string name = va_arg!(string)(_argptr); 169 170 if ( _arguments[i+1] == typeid(bool) || 171 _arguments[i+1] == typeid(int) || 172 _arguments[i+1] == typeid(GtkJustification) || 173 _arguments[i+1] == typeid(GtkTextDirection) || 174 _arguments[i+1] == typeid(GtkWrapMode) || 175 _arguments[i+1] == typeid(PangoStretch) || 176 _arguments[i+1] == typeid(PangoStyle) || 177 _arguments[i+1] == typeid(PangoUnderline) || 178 _arguments[i+1] == typeid(PangoVariant) || 179 _arguments[i+1] == typeid(PangoWeight) ) 180 { 181 182 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(int)(_argptr), null); 183 } 184 else if ( _arguments[i+1] == typeid(double) ) 185 { 186 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(double)(_argptr), null); 187 } 188 else if ( _arguments[i+1] == typeid(const(double)) ) 189 { 190 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(double)(_argptr), null); 191 } 192 else if ( _arguments[i+1] == typeid(PgFontDescription) ) 193 { 194 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(PgFontDescription)(_argptr).getPgFontDescriptionStruct(), null); 195 } 196 else if ( _arguments[i+1] == typeid(PgTabArray) ) 197 { 198 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(PgTabArray)(_argptr).getPgTabArrayStruct(), null); 199 } 200 else if ( _arguments[i+1] == typeid(string) ) 201 { 202 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), Str.toStringz(va_arg!(string)(_argptr)), null); 203 } 204 else 205 { 206 stderr.writefln("TextBuffer.CreateTag: Unsupported type: \"%s\" for property: \"%s\"", _arguments[i+1], name); 207 208 //TODO: throw segfaults, druntime bug? 209 throw new Exception("TextBuffer.CreateTag: Unsupported type: \""~_arguments[i+1].toString()~"\" for property: \""~name~"\""); 210 } 211 } 212 213 return tag; 214 } 215 216 /** 217 * Obtain the entire text 218 * Returns: The text string 219 */ 220 string getText() 221 { 222 TextIter start = new TextIter(); 223 TextIter end = new TextIter(); 224 getBounds(start,end); 225 return Str.toString(gtk_text_buffer_get_slice(gtkTextBuffer, start.getTextIterStruct(), end.getTextIterStruct(), true)); 226 } 227 228 /** 229 */ 230 231 /** */ 232 public static GType getType() 233 { 234 return gtk_text_buffer_get_type(); 235 } 236 237 /** 238 * Creates a new text buffer. 239 * 240 * Params: 241 * table = a tag table, or %NULL to create a new one 242 * 243 * Returns: a new text buffer 244 * 245 * Throws: ConstructionException GTK+ fails to create the object. 246 */ 247 public this(TextTagTable table) 248 { 249 auto __p = gtk_text_buffer_new((table is null) ? null : table.getTextTagTableStruct()); 250 251 if(__p is null) 252 { 253 throw new ConstructionException("null returned by new"); 254 } 255 256 this(cast(GtkTextBuffer*) __p, true); 257 } 258 259 /** 260 * Adds the mark at position @where. 261 * 262 * The mark must not be added to another buffer, and if its name 263 * is not %NULL then there must not be another mark in the buffer 264 * with the same name. 265 * 266 * Emits the [signal@Gtk.TextBuffer::mark-set] signal as notification 267 * of the mark's initial placement. 268 * 269 * Params: 270 * mark = the mark to add 271 * where = location to place mark 272 */ 273 public void addMark(TextMark mark, TextIter where) 274 { 275 gtk_text_buffer_add_mark(gtkTextBuffer, (mark is null) ? null : mark.getTextMarkStruct(), (where is null) ? null : where.getTextIterStruct()); 276 } 277 278 /** 279 * Adds @clipboard to the list of clipboards in which the selection 280 * contents of @buffer are available. 281 * 282 * In most cases, @clipboard will be the `GdkClipboard` returned by 283 * [method@Gtk.Widget.get_primary_clipboard] for a view of @buffer. 284 * 285 * Params: 286 * clipboard = a `GdkClipboard` 287 */ 288 public void addSelectionClipboard(Clipboard clipboard) 289 { 290 gtk_text_buffer_add_selection_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct()); 291 } 292 293 /** 294 * Emits the “apply-tag” signal on @buffer. 295 * 296 * The default handler for the signal applies 297 * @tag to the given range. @start and @end do 298 * not have to be in order. 299 * 300 * Params: 301 * tag = a `GtkTextTag` 302 * start = one bound of range to be tagged 303 * end = other bound of range to be tagged 304 */ 305 public void applyTag(TextTag tag, TextIter start, TextIter end) 306 { 307 gtk_text_buffer_apply_tag(gtkTextBuffer, (tag is null) ? null : tag.getTextTagStruct(), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 308 } 309 310 /** 311 * Emits the “apply-tag” signal on @buffer. 312 * 313 * Calls [method@Gtk.TextTagTable.lookup] on the buffer’s 314 * tag table to get a `GtkTextTag`, then calls 315 * [method@Gtk.TextBuffer.apply_tag]. 316 * 317 * Params: 318 * name = name of a named `GtkTextTag` 319 * start = one bound of range to be tagged 320 * end = other bound of range to be tagged 321 */ 322 public void applyTagByName(string name, TextIter start, TextIter end) 323 { 324 gtk_text_buffer_apply_tag_by_name(gtkTextBuffer, Str.toStringz(name), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 325 } 326 327 /** 328 * Performs the appropriate action as if the user hit the delete 329 * key with the cursor at the position specified by @iter. 330 * 331 * In the normal case a single character will be deleted, but when 332 * combining accents are involved, more than one character can 333 * be deleted, and when precomposed character and accent combinations 334 * are involved, less than one character will be deleted. 335 * 336 * Because the buffer is modified, all outstanding iterators become 337 * invalid after calling this function; however, the @iter will be 338 * re-initialized to point to the location where text was deleted. 339 * 340 * Params: 341 * iter = a position in @buffer 342 * interactive = whether the deletion is caused by user interaction 343 * defaultEditable = whether the buffer is editable by default 344 * 345 * Returns: %TRUE if the buffer was modified 346 */ 347 public bool backspace(TextIter iter, bool interactive, bool defaultEditable) 348 { 349 return gtk_text_buffer_backspace(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), interactive, defaultEditable) != 0; 350 } 351 352 /** 353 * Denotes the beginning of an action that may not be undone. 354 * 355 * This will cause any previous operations in the undo/redo queue 356 * to be cleared. 357 * 358 * This should be paired with a call to 359 * [method@Gtk.TextBuffer.end_irreversible_action] after the irreversible 360 * action has completed. 361 * 362 * You may nest calls to gtk_text_buffer_begin_irreversible_action() 363 * and gtk_text_buffer_end_irreversible_action() pairs. 364 */ 365 public void beginIrreversibleAction() 366 { 367 gtk_text_buffer_begin_irreversible_action(gtkTextBuffer); 368 } 369 370 /** 371 * Called to indicate that the buffer operations between here and a 372 * call to gtk_text_buffer_end_user_action() are part of a single 373 * user-visible operation. 374 * 375 * The operations between gtk_text_buffer_begin_user_action() and 376 * gtk_text_buffer_end_user_action() can then be grouped when creating 377 * an undo stack. `GtkTextBuffer` maintains a count of calls to 378 * gtk_text_buffer_begin_user_action() that have not been closed with 379 * a call to gtk_text_buffer_end_user_action(), and emits the 380 * “begin-user-action” and “end-user-action” signals only for the 381 * outermost pair of calls. This allows you to build user actions 382 * from other user actions. 383 * 384 * The “interactive” buffer mutation functions, such as 385 * [method@Gtk.TextBuffer.insert_interactive], automatically call 386 * begin/end user action around the buffer operations they perform, 387 * so there's no need to add extra calls if you user action consists 388 * solely of a single call to one of those functions. 389 */ 390 public void beginUserAction() 391 { 392 gtk_text_buffer_begin_user_action(gtkTextBuffer); 393 } 394 395 /** 396 * Copies the currently-selected text to a clipboard. 397 * 398 * Params: 399 * clipboard = the `GdkClipboard` object to copy to 400 */ 401 public void copyClipboard(Clipboard clipboard) 402 { 403 gtk_text_buffer_copy_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct()); 404 } 405 406 /** 407 * Creates and inserts a child anchor. 408 * 409 * This is a convenience function which simply creates a child anchor 410 * with [ctor@Gtk.TextChildAnchor.new] and inserts it into the buffer 411 * with [method@Gtk.TextBuffer.insert_child_anchor]. 412 * 413 * The new anchor is owned by the buffer; no reference count is 414 * returned to the caller of this function. 415 * 416 * Params: 417 * iter = location in the buffer 418 * 419 * Returns: the created child anchor 420 */ 421 public TextChildAnchor createChildAnchor(TextIter iter) 422 { 423 auto __p = gtk_text_buffer_create_child_anchor(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct()); 424 425 if(__p is null) 426 { 427 return null; 428 } 429 430 return ObjectG.getDObject!(TextChildAnchor)(cast(GtkTextChildAnchor*) __p); 431 } 432 433 /** 434 * Creates a mark at position @where. 435 * 436 * If @mark_name is %NULL, the mark is anonymous; otherwise, the mark 437 * can be retrieved by name using [method@Gtk.TextBuffer.get_mark]. 438 * If a mark has left gravity, and text is inserted at the mark’s 439 * current location, the mark will be moved to the left of the 440 * newly-inserted text. If the mark has right gravity 441 * (@left_gravity = %FALSE), the mark will end up on the right of 442 * newly-inserted text. The standard left-to-right cursor is a mark 443 * with right gravity (when you type, the cursor stays on the right 444 * side of the text you’re typing). 445 * 446 * The caller of this function does not own a 447 * reference to the returned `GtkTextMark`, so you can ignore the 448 * return value if you like. Marks are owned by the buffer and go 449 * away when the buffer does. 450 * 451 * Emits the [signal@Gtk.TextBuffer::mark-set] signal as notification 452 * of the mark's initial placement. 453 * 454 * Params: 455 * markName = name for mark 456 * where = location to place mark 457 * leftGravity = whether the mark has left gravity 458 * 459 * Returns: the new `GtkTextMark` object 460 */ 461 public TextMark createMark(string markName, TextIter where, bool leftGravity) 462 { 463 auto __p = gtk_text_buffer_create_mark(gtkTextBuffer, Str.toStringz(markName), (where is null) ? null : where.getTextIterStruct(), leftGravity); 464 465 if(__p is null) 466 { 467 return null; 468 } 469 470 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) __p); 471 } 472 473 /** 474 * Copies the currently-selected text to a clipboard, 475 * then deletes said text if it’s editable. 476 * 477 * Params: 478 * clipboard = the `GdkClipboard` object to cut to 479 * defaultEditable = default editability of the buffer 480 */ 481 public void cutClipboard(Clipboard clipboard, bool defaultEditable) 482 { 483 gtk_text_buffer_cut_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct(), defaultEditable); 484 } 485 486 alias delet = delete_; 487 /** 488 * Deletes text between @start and @end. 489 * 490 * The order of @start and @end is not actually relevant; 491 * gtk_text_buffer_delete() will reorder them. 492 * 493 * This function actually emits the “delete-range” signal, and 494 * the default handler of that signal deletes the text. Because the 495 * buffer is modified, all outstanding iterators become invalid after 496 * calling this function; however, the @start and @end will be 497 * re-initialized to point to the location where text was deleted. 498 * 499 * Params: 500 * start = a position in @buffer 501 * end = another position in @buffer 502 */ 503 public void delete_(TextIter start, TextIter end) 504 { 505 gtk_text_buffer_delete(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 506 } 507 508 /** 509 * Deletes all editable text in the given range. 510 * 511 * Calls [method@Gtk.TextBuffer.delete] for each editable 512 * sub-range of [@start,@end). @start and @end are revalidated 513 * to point to the location of the last deleted range, or left 514 * untouched if no text was deleted. 515 * 516 * Params: 517 * startIter = start of range to delete 518 * endIter = end of range 519 * defaultEditable = whether the buffer is editable by default 520 * 521 * Returns: whether some text was actually deleted 522 */ 523 public bool deleteInteractive(TextIter startIter, TextIter endIter, bool defaultEditable) 524 { 525 return gtk_text_buffer_delete_interactive(gtkTextBuffer, (startIter is null) ? null : startIter.getTextIterStruct(), (endIter is null) ? null : endIter.getTextIterStruct(), defaultEditable) != 0; 526 } 527 528 /** 529 * Deletes @mark, so that it’s no longer located anywhere in the 530 * buffer. 531 * 532 * Removes the reference the buffer holds to the mark, so if 533 * you haven’t called g_object_ref() on the mark, it will be freed. 534 * Even if the mark isn’t freed, most operations on @mark become 535 * invalid, until it gets added to a buffer again with 536 * [method@Gtk.TextBuffer.add_mark]. Use [method@Gtk.TextMark.get_deleted] 537 * to find out if a mark has been removed from its buffer. 538 * 539 * The [signal@Gtk.TextBuffer::mark-deleted] signal will be emitted as 540 * notification after the mark is deleted. 541 * 542 * Params: 543 * mark = a `GtkTextMark` in @buffer 544 */ 545 public void deleteMark(TextMark mark) 546 { 547 gtk_text_buffer_delete_mark(gtkTextBuffer, (mark is null) ? null : mark.getTextMarkStruct()); 548 } 549 550 /** 551 * Deletes the mark named @name; the mark must exist. 552 * 553 * See [method@Gtk.TextBuffer.delete_mark] for details. 554 * 555 * Params: 556 * name = name of a mark in @buffer 557 */ 558 public void deleteMarkByName(string name) 559 { 560 gtk_text_buffer_delete_mark_by_name(gtkTextBuffer, Str.toStringz(name)); 561 } 562 563 /** 564 * Deletes the range between the “insert” and “selection_bound” marks, 565 * that is, the currently-selected text. 566 * 567 * If @interactive is %TRUE, the editability of the selection will be 568 * considered (users can’t delete uneditable text). 569 * 570 * Params: 571 * interactive = whether the deletion is caused by user interaction 572 * defaultEditable = whether the buffer is editable by default 573 * 574 * Returns: whether there was a non-empty selection to delete 575 */ 576 public bool deleteSelection(bool interactive, bool defaultEditable) 577 { 578 return gtk_text_buffer_delete_selection(gtkTextBuffer, interactive, defaultEditable) != 0; 579 } 580 581 /** 582 * Denotes the end of an action that may not be undone. 583 * 584 * This will cause any previous operations in the undo/redo 585 * queue to be cleared. 586 * 587 * This should be called after completing modifications to the 588 * text buffer after [method@Gtk.TextBuffer.begin_irreversible_action] 589 * was called. 590 * 591 * You may nest calls to gtk_text_buffer_begin_irreversible_action() 592 * and gtk_text_buffer_end_irreversible_action() pairs. 593 */ 594 public void endIrreversibleAction() 595 { 596 gtk_text_buffer_end_irreversible_action(gtkTextBuffer); 597 } 598 599 /** 600 * Ends a user-visible operation. 601 * 602 * Should be paired with a call to 603 * [method@Gtk.TextBuffer.begin_user_action]. 604 * See that function for a full explanation. 605 */ 606 public void endUserAction() 607 { 608 gtk_text_buffer_end_user_action(gtkTextBuffer); 609 } 610 611 /** 612 * Retrieves the first and last iterators in the buffer, i.e. the 613 * entire buffer lies within the range [@start,@end). 614 * 615 * Params: 616 * start = iterator to initialize with first position in the buffer 617 * end = iterator to initialize with the end iterator 618 */ 619 public void getBounds(out TextIter start, out TextIter end) 620 { 621 GtkTextIter* outstart = sliceNew!GtkTextIter(); 622 GtkTextIter* outend = sliceNew!GtkTextIter(); 623 624 gtk_text_buffer_get_bounds(gtkTextBuffer, outstart, outend); 625 626 start = ObjectG.getDObject!(TextIter)(outstart, true); 627 end = ObjectG.getDObject!(TextIter)(outend, true); 628 } 629 630 /** 631 * Gets whether there is a redoable action in the history. 632 * 633 * Returns: %TRUE if there is an redoable action 634 */ 635 public bool getCanRedo() 636 { 637 return gtk_text_buffer_get_can_redo(gtkTextBuffer) != 0; 638 } 639 640 /** 641 * Gets whether there is an undoable action in the history. 642 * 643 * Returns: %TRUE if there is an undoable action 644 */ 645 public bool getCanUndo() 646 { 647 return gtk_text_buffer_get_can_undo(gtkTextBuffer) != 0; 648 } 649 650 /** 651 * Gets the number of characters in the buffer. 652 * 653 * Note that characters and bytes are not the same, you can’t e.g. 654 * expect the contents of the buffer in string form to be this 655 * many bytes long. 656 * 657 * The character count is cached, so this function is very fast. 658 * 659 * Returns: number of characters in the buffer 660 */ 661 public int getCharCount() 662 { 663 return gtk_text_buffer_get_char_count(gtkTextBuffer); 664 } 665 666 /** 667 * Gets whether the buffer is saving modifications to the buffer 668 * to allow for undo and redo actions. 669 * 670 * See [method@Gtk.TextBuffer.begin_irreversible_action] and 671 * [method@Gtk.TextBuffer.end_irreversible_action] to create 672 * changes to the buffer that cannot be undone. 673 */ 674 public bool getEnableUndo() 675 { 676 return gtk_text_buffer_get_enable_undo(gtkTextBuffer) != 0; 677 } 678 679 /** 680 * Initializes @iter with the “end iterator,” one past the last valid 681 * character in the text buffer. 682 * 683 * If dereferenced with [method@Gtk.TextIter.get_char], the end 684 * iterator has a character value of 0. 685 * The entire buffer lies in the range from the first position in 686 * the buffer (call [method@Gtk.TextBuffer.get_start_iter] to get 687 * character position 0) to the end iterator. 688 * 689 * Params: 690 * iter = iterator to initialize 691 */ 692 public void getEndIter(out TextIter iter) 693 { 694 GtkTextIter* outiter = sliceNew!GtkTextIter(); 695 696 gtk_text_buffer_get_end_iter(gtkTextBuffer, outiter); 697 698 iter = ObjectG.getDObject!(TextIter)(outiter, true); 699 } 700 701 /** 702 * Indicates whether the buffer has some text currently selected. 703 * 704 * Returns: %TRUE if the there is text selected 705 */ 706 public bool getHasSelection() 707 { 708 return gtk_text_buffer_get_has_selection(gtkTextBuffer) != 0; 709 } 710 711 /** 712 * Returns the mark that represents the cursor (insertion point). 713 * 714 * Equivalent to calling [method@Gtk.TextBuffer.get_mark] 715 * to get the mark named “insert”, but very slightly more 716 * efficient, and involves less typing. 717 * 718 * Returns: insertion point mark 719 */ 720 public TextMark getInsert() 721 { 722 auto __p = gtk_text_buffer_get_insert(gtkTextBuffer); 723 724 if(__p is null) 725 { 726 return null; 727 } 728 729 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) __p); 730 } 731 732 /** 733 * Obtains the location of @anchor within @buffer. 734 * 735 * Params: 736 * iter = an iterator to be initialized 737 * anchor = a child anchor that appears in @buffer 738 */ 739 public void getIterAtChildAnchor(out TextIter iter, TextChildAnchor anchor) 740 { 741 GtkTextIter* outiter = sliceNew!GtkTextIter(); 742 743 gtk_text_buffer_get_iter_at_child_anchor(gtkTextBuffer, outiter, (anchor is null) ? null : anchor.getTextChildAnchorStruct()); 744 745 iter = ObjectG.getDObject!(TextIter)(outiter, true); 746 } 747 748 /** 749 * Initializes @iter to the start of the given line. 750 * 751 * If @line_number is greater than or equal to the number of lines 752 * in the @buffer, the end iterator is returned. 753 * 754 * Params: 755 * iter = iterator to initialize 756 * lineNumber = line number counting from 0 757 * 758 * Returns: whether the exact position has been found 759 */ 760 public bool getIterAtLine(out TextIter iter, int lineNumber) 761 { 762 GtkTextIter* outiter = sliceNew!GtkTextIter(); 763 764 auto __p = gtk_text_buffer_get_iter_at_line(gtkTextBuffer, outiter, lineNumber) != 0; 765 766 iter = ObjectG.getDObject!(TextIter)(outiter, true); 767 768 return __p; 769 } 770 771 /** 772 * Obtains an iterator pointing to @byte_index within the given line. 773 * 774 * @byte_index must be the start of a UTF-8 character. Note bytes, not 775 * characters; UTF-8 may encode one character as multiple bytes. 776 * 777 * If @line_number is greater than or equal to the number of lines in the @buffer, 778 * the end iterator is returned. And if @byte_index is off the 779 * end of the line, the iterator at the end of the line is returned. 780 * 781 * Params: 782 * iter = iterator to initialize 783 * lineNumber = line number counting from 0 784 * byteIndex = byte index from start of line 785 * 786 * Returns: whether the exact position has been found 787 */ 788 public bool getIterAtLineIndex(out TextIter iter, int lineNumber, int byteIndex) 789 { 790 GtkTextIter* outiter = sliceNew!GtkTextIter(); 791 792 auto __p = gtk_text_buffer_get_iter_at_line_index(gtkTextBuffer, outiter, lineNumber, byteIndex) != 0; 793 794 iter = ObjectG.getDObject!(TextIter)(outiter, true); 795 796 return __p; 797 } 798 799 /** 800 * Obtains an iterator pointing to @char_offset within the given line. 801 * 802 * Note characters, not bytes; UTF-8 may encode one character as multiple 803 * bytes. 804 * 805 * If @line_number is greater than or equal to the number of lines in the @buffer, 806 * the end iterator is returned. And if @char_offset is off the 807 * end of the line, the iterator at the end of the line is returned. 808 * 809 * Params: 810 * iter = iterator to initialize 811 * lineNumber = line number counting from 0 812 * charOffset = char offset from start of line 813 * 814 * Returns: whether the exact position has been found 815 */ 816 public bool getIterAtLineOffset(out TextIter iter, int lineNumber, int charOffset) 817 { 818 GtkTextIter* outiter = sliceNew!GtkTextIter(); 819 820 auto __p = gtk_text_buffer_get_iter_at_line_offset(gtkTextBuffer, outiter, lineNumber, charOffset) != 0; 821 822 iter = ObjectG.getDObject!(TextIter)(outiter, true); 823 824 return __p; 825 } 826 827 /** 828 * Initializes @iter with the current position of @mark. 829 * 830 * Params: 831 * iter = iterator to initialize 832 * mark = a `GtkTextMark` in @buffer 833 */ 834 public void getIterAtMark(out TextIter iter, TextMark mark) 835 { 836 GtkTextIter* outiter = sliceNew!GtkTextIter(); 837 838 gtk_text_buffer_get_iter_at_mark(gtkTextBuffer, outiter, (mark is null) ? null : mark.getTextMarkStruct()); 839 840 iter = ObjectG.getDObject!(TextIter)(outiter, true); 841 } 842 843 /** 844 * Initializes @iter to a position @char_offset chars from the start 845 * of the entire buffer. 846 * 847 * If @char_offset is -1 or greater than the number 848 * of characters in the buffer, @iter is initialized to the end iterator, 849 * the iterator one past the last valid character in the buffer. 850 * 851 * Params: 852 * iter = iterator to initialize 853 * charOffset = char offset from start of buffer, counting from 0, or -1 854 */ 855 public void getIterAtOffset(out TextIter iter, int charOffset) 856 { 857 GtkTextIter* outiter = sliceNew!GtkTextIter(); 858 859 gtk_text_buffer_get_iter_at_offset(gtkTextBuffer, outiter, charOffset); 860 861 iter = ObjectG.getDObject!(TextIter)(outiter, true); 862 } 863 864 /** 865 * Obtains the number of lines in the buffer. 866 * 867 * This value is cached, so the function is very fast. 868 * 869 * Returns: number of lines in the buffer 870 */ 871 public int getLineCount() 872 { 873 return gtk_text_buffer_get_line_count(gtkTextBuffer); 874 } 875 876 /** 877 * Returns the mark named @name in buffer @buffer, or %NULL if no such 878 * mark exists in the buffer. 879 * 880 * Params: 881 * name = a mark name 882 * 883 * Returns: a `GtkTextMark` 884 */ 885 public TextMark getMark(string name) 886 { 887 auto __p = gtk_text_buffer_get_mark(gtkTextBuffer, Str.toStringz(name)); 888 889 if(__p is null) 890 { 891 return null; 892 } 893 894 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) __p); 895 } 896 897 /** 898 * Gets the maximum number of undo levels to perform. 899 * 900 * If 0, unlimited undo actions may be performed. Note that this may 901 * have a memory usage impact as it requires storing an additional 902 * copy of the inserted or removed text within the text buffer. 903 */ 904 public uint getMaxUndoLevels() 905 { 906 return gtk_text_buffer_get_max_undo_levels(gtkTextBuffer); 907 } 908 909 /** 910 * Indicates whether the buffer has been modified since the last call 911 * to [method@Gtk.TextBuffer.set_modified] set the modification flag to 912 * %FALSE. 913 * 914 * Used for example to enable a “save” function in a text editor. 915 * 916 * Returns: %TRUE if the buffer has been modified 917 */ 918 public bool getModified() 919 { 920 return gtk_text_buffer_get_modified(gtkTextBuffer) != 0; 921 } 922 923 /** 924 * Returns the mark that represents the selection bound. 925 * 926 * Equivalent to calling [method@Gtk.TextBuffer.get_mark] 927 * to get the mark named “selection_bound”, but very slightly 928 * more efficient, and involves less typing. 929 * 930 * The currently-selected text in @buffer is the region between the 931 * “selection_bound” and “insert” marks. If “selection_bound” and 932 * “insert” are in the same place, then there is no current selection. 933 * [method@Gtk.TextBuffer.get_selection_bounds] is another convenient 934 * function for handling the selection, if you just want to know whether 935 * there’s a selection and what its bounds are. 936 * 937 * Returns: selection bound mark 938 */ 939 public TextMark getSelectionBound() 940 { 941 auto __p = gtk_text_buffer_get_selection_bound(gtkTextBuffer); 942 943 if(__p is null) 944 { 945 return null; 946 } 947 948 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) __p); 949 } 950 951 /** 952 * Returns %TRUE if some text is selected; places the bounds 953 * of the selection in @start and @end. 954 * 955 * If the selection has length 0, then @start and @end are filled 956 * in with the same value. @start and @end will be in ascending order. 957 * If @start and @end are %NULL, then they are not filled in, but the 958 * return value still indicates whether text is selected. 959 * 960 * Params: 961 * start = iterator to initialize with selection start 962 * end = iterator to initialize with selection end 963 * 964 * Returns: whether the selection has nonzero length 965 */ 966 public bool getSelectionBounds(out TextIter start, out TextIter end) 967 { 968 GtkTextIter* outstart = sliceNew!GtkTextIter(); 969 GtkTextIter* outend = sliceNew!GtkTextIter(); 970 971 auto __p = gtk_text_buffer_get_selection_bounds(gtkTextBuffer, outstart, outend) != 0; 972 973 start = ObjectG.getDObject!(TextIter)(outstart, true); 974 end = ObjectG.getDObject!(TextIter)(outend, true); 975 976 return __p; 977 } 978 979 /** 980 * Get a content provider for this buffer. 981 * 982 * It can be used to make the content of @buffer available 983 * in a `GdkClipboard`, see [method@Gdk.Clipboard.set_content]. 984 * 985 * Returns: a new `GdkContentProvider`. 986 */ 987 public ContentProvider getSelectionContent() 988 { 989 auto __p = gtk_text_buffer_get_selection_content(gtkTextBuffer); 990 991 if(__p is null) 992 { 993 return null; 994 } 995 996 return ObjectG.getDObject!(ContentProvider)(cast(GdkContentProvider*) __p, true); 997 } 998 999 /** 1000 * Returns the text in the range [@start,@end). 1001 * 1002 * Excludes undisplayed text (text marked with tags that set the 1003 * invisibility attribute) if @include_hidden_chars is %FALSE. 1004 * The returned string includes a 0xFFFC character whenever the 1005 * buffer contains embedded images, so byte and character indexes 1006 * into the returned string do correspond to byte and character 1007 * indexes into the buffer. Contrast with [method@Gtk.TextBuffer.get_text]. 1008 * Note that 0xFFFC can occur in normal text as well, so it is not a 1009 * reliable indicator that a paintable or widget is in the buffer. 1010 * 1011 * Params: 1012 * start = start of a range 1013 * end = end of a range 1014 * includeHiddenChars = whether to include invisible text 1015 * 1016 * Returns: an allocated UTF-8 string 1017 */ 1018 public string getSlice(TextIter start, TextIter end, bool includeHiddenChars) 1019 { 1020 auto retStr = gtk_text_buffer_get_slice(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), includeHiddenChars); 1021 1022 scope(exit) Str.freeString(retStr); 1023 return Str.toString(retStr); 1024 } 1025 1026 /** 1027 * Initialized @iter with the first position in the text buffer. 1028 * 1029 * This is the same as using [method@Gtk.TextBuffer.get_iter_at_offset] 1030 * to get the iter at character offset 0. 1031 * 1032 * Params: 1033 * iter = iterator to initialize 1034 */ 1035 public void getStartIter(out TextIter iter) 1036 { 1037 GtkTextIter* outiter = sliceNew!GtkTextIter(); 1038 1039 gtk_text_buffer_get_start_iter(gtkTextBuffer, outiter); 1040 1041 iter = ObjectG.getDObject!(TextIter)(outiter, true); 1042 } 1043 1044 /** 1045 * Get the `GtkTextTagTable` associated with this buffer. 1046 * 1047 * Returns: the buffer’s tag table 1048 */ 1049 public TextTagTable getTagTable() 1050 { 1051 auto __p = gtk_text_buffer_get_tag_table(gtkTextBuffer); 1052 1053 if(__p is null) 1054 { 1055 return null; 1056 } 1057 1058 return ObjectG.getDObject!(TextTagTable)(cast(GtkTextTagTable*) __p); 1059 } 1060 1061 /** 1062 * Returns the text in the range [@start,@end). 1063 * 1064 * Excludes undisplayed text (text marked with tags that set the 1065 * invisibility attribute) if @include_hidden_chars is %FALSE. 1066 * Does not include characters representing embedded images, so 1067 * byte and character indexes into the returned string do not 1068 * correspond to byte and character indexes into the buffer. 1069 * Contrast with [method@Gtk.TextBuffer.get_slice]. 1070 * 1071 * Params: 1072 * start = start of a range 1073 * end = end of a range 1074 * includeHiddenChars = whether to include invisible text 1075 * 1076 * Returns: an allocated UTF-8 string 1077 */ 1078 public string getText(TextIter start, TextIter end, bool includeHiddenChars) 1079 { 1080 auto retStr = gtk_text_buffer_get_text(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), includeHiddenChars); 1081 1082 scope(exit) Str.freeString(retStr); 1083 return Str.toString(retStr); 1084 } 1085 1086 /** 1087 * Inserts @len bytes of @text at position @iter. 1088 * 1089 * If @len is -1, @text must be nul-terminated and will be inserted in its 1090 * entirety. Emits the “insert-text” signal; insertion actually occurs 1091 * in the default handler for the signal. @iter is invalidated when 1092 * insertion occurs (because the buffer contents change), but the 1093 * default signal handler revalidates it to point to the end of the 1094 * inserted text. 1095 * 1096 * Params: 1097 * iter = a position in the buffer 1098 * text = text in UTF-8 format 1099 */ 1100 public void insert(TextIter iter, string text) 1101 { 1102 gtk_text_buffer_insert(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(text), cast(int)text.length); 1103 } 1104 1105 /** 1106 * Inserts @text in @buffer. 1107 * 1108 * Simply calls [method@Gtk.TextBuffer.insert], 1109 * using the current cursor position as the insertion point. 1110 * 1111 * Params: 1112 * text = text in UTF-8 format 1113 */ 1114 public void insertAtCursor(string text) 1115 { 1116 gtk_text_buffer_insert_at_cursor(gtkTextBuffer, Str.toStringz(text), cast(int)text.length); 1117 } 1118 1119 /** 1120 * Inserts a child widget anchor into the text buffer at @iter. 1121 * 1122 * The anchor will be counted as one character in character counts, and 1123 * when obtaining the buffer contents as a string, will be represented 1124 * by the Unicode “object replacement character” 0xFFFC. Note that the 1125 * “slice” variants for obtaining portions of the buffer as a string 1126 * include this character for child anchors, but the “text” variants do 1127 * not. E.g. see [method@Gtk.TextBuffer.get_slice] and 1128 * [method@Gtk.TextBuffer.get_text]. 1129 * 1130 * Consider [method@Gtk.TextBuffer.create_child_anchor] as a more 1131 * convenient alternative to this function. The buffer will add a 1132 * reference to the anchor, so you can unref it after insertion. 1133 * 1134 * Params: 1135 * iter = location to insert the anchor 1136 * anchor = a `GtkTextChildAnchor` 1137 */ 1138 public void insertChildAnchor(TextIter iter, TextChildAnchor anchor) 1139 { 1140 gtk_text_buffer_insert_child_anchor(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (anchor is null) ? null : anchor.getTextChildAnchorStruct()); 1141 } 1142 1143 /** 1144 * Inserts @text in @buffer. 1145 * 1146 * Like [method@Gtk.TextBuffer.insert], but the insertion will not occur 1147 * if @iter is at a non-editable location in the buffer. Usually you 1148 * want to prevent insertions at ineditable locations if the insertion 1149 * results from a user action (is interactive). 1150 * 1151 * @default_editable indicates the editability of text that doesn't 1152 * have a tag affecting editability applied to it. Typically the 1153 * result of [method@Gtk.TextView.get_editable] is appropriate here. 1154 * 1155 * Params: 1156 * iter = a position in @buffer 1157 * text = some UTF-8 text 1158 * defaultEditable = default editability of buffer 1159 * 1160 * Returns: whether text was actually inserted 1161 */ 1162 public bool insertInteractive(TextIter iter, string text, bool defaultEditable) 1163 { 1164 return gtk_text_buffer_insert_interactive(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(text), cast(int)text.length, defaultEditable) != 0; 1165 } 1166 1167 /** 1168 * Inserts @text in @buffer. 1169 * 1170 * Calls [method@Gtk.TextBuffer.insert_interactive] 1171 * at the cursor position. 1172 * 1173 * @default_editable indicates the editability of text that doesn't 1174 * have a tag affecting editability applied to it. Typically the 1175 * result of [method@Gtk.TextView.get_editable] is appropriate here. 1176 * 1177 * Params: 1178 * text = text in UTF-8 format 1179 * defaultEditable = default editability of buffer 1180 * 1181 * Returns: whether text was actually inserted 1182 */ 1183 public bool insertInteractiveAtCursor(string text, bool defaultEditable) 1184 { 1185 return gtk_text_buffer_insert_interactive_at_cursor(gtkTextBuffer, Str.toStringz(text), cast(int)text.length, defaultEditable) != 0; 1186 } 1187 1188 /** 1189 * Inserts the text in @markup at position @iter. 1190 * 1191 * @markup will be inserted in its entirety and must be nul-terminated 1192 * and valid UTF-8. Emits the [signal@Gtk.TextBuffer::insert-text] signal, 1193 * possibly multiple times; insertion actually occurs in the default handler 1194 * for the signal. @iter will point to the end of the inserted text on return. 1195 * 1196 * Params: 1197 * iter = location to insert the markup 1198 * markup = a nul-terminated UTF-8 string containing Pango markup 1199 * len = length of @markup in bytes, or -1 1200 */ 1201 public void insertMarkup(TextIter iter, string markup, int len) 1202 { 1203 gtk_text_buffer_insert_markup(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(markup), len); 1204 } 1205 1206 /** 1207 * Inserts an image into the text buffer at @iter. 1208 * 1209 * The image will be counted as one character in character counts, 1210 * and when obtaining the buffer contents as a string, will be 1211 * represented by the Unicode “object replacement character” 0xFFFC. 1212 * Note that the “slice” variants for obtaining portions of the buffer 1213 * as a string include this character for paintable, but the “text” 1214 * variants do not. e.g. see [method@Gtk.TextBuffer.get_slice] and 1215 * [method@Gtk.TextBuffer.get_text]. 1216 * 1217 * Params: 1218 * iter = location to insert the paintable 1219 * paintable = a `GdkPaintable` 1220 */ 1221 public void insertPaintable(TextIter iter, PaintableIF paintable) 1222 { 1223 gtk_text_buffer_insert_paintable(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (paintable is null) ? null : paintable.getPaintableStruct()); 1224 } 1225 1226 /** 1227 * Copies text, tags, and paintables between @start and @end 1228 * and inserts the copy at @iter. 1229 * 1230 * The order of @start and @end doesn’t matter. 1231 * 1232 * Used instead of simply getting/inserting text because it preserves 1233 * images and tags. If @start and @end are in a different buffer from 1234 * @buffer, the two buffers must share the same tag table. 1235 * 1236 * Implemented via emissions of the ::insert-text and ::apply-tag signals, 1237 * so expect those. 1238 * 1239 * Params: 1240 * iter = a position in @buffer 1241 * start = a position in a `GtkTextBuffer` 1242 * end = another position in the same buffer as @start 1243 */ 1244 public void insertRange(TextIter iter, TextIter start, TextIter end) 1245 { 1246 gtk_text_buffer_insert_range(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1247 } 1248 1249 /** 1250 * Copies text, tags, and paintables between @start and @end 1251 * and inserts the copy at @iter. 1252 * 1253 * Same as [method@Gtk.TextBuffer.insert_range], but does nothing 1254 * if the insertion point isn’t editable. The @default_editable 1255 * parameter indicates whether the text is editable at @iter if 1256 * no tags enclosing @iter affect editability. Typically the result 1257 * of [method@Gtk.TextView.get_editable] is appropriate here. 1258 * 1259 * Params: 1260 * iter = a position in @buffer 1261 * start = a position in a `GtkTextBuffer` 1262 * end = another position in the same buffer as @start 1263 * defaultEditable = default editability of the buffer 1264 * 1265 * Returns: whether an insertion was possible at @iter 1266 */ 1267 public bool insertRangeInteractive(TextIter iter, TextIter start, TextIter end, bool defaultEditable) 1268 { 1269 return gtk_text_buffer_insert_range_interactive(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), defaultEditable) != 0; 1270 } 1271 1272 /** 1273 * Moves @mark to the new location @where. 1274 * 1275 * Emits the [signal@Gtk.TextBuffer::mark-set] signal 1276 * as notification of the move. 1277 * 1278 * Params: 1279 * mark = a `GtkTextMark` 1280 * where = new location for @mark in @buffer 1281 */ 1282 public void moveMark(TextMark mark, TextIter where) 1283 { 1284 gtk_text_buffer_move_mark(gtkTextBuffer, (mark is null) ? null : mark.getTextMarkStruct(), (where is null) ? null : where.getTextIterStruct()); 1285 } 1286 1287 /** 1288 * Moves the mark named @name (which must exist) to location @where. 1289 * 1290 * See [method@Gtk.TextBuffer.move_mark] for details. 1291 * 1292 * Params: 1293 * name = name of a mark 1294 * where = new location for mark 1295 */ 1296 public void moveMarkByName(string name, TextIter where) 1297 { 1298 gtk_text_buffer_move_mark_by_name(gtkTextBuffer, Str.toStringz(name), (where is null) ? null : where.getTextIterStruct()); 1299 } 1300 1301 /** 1302 * Pastes the contents of a clipboard. 1303 * 1304 * If @override_location is %NULL, the pasted text will be inserted 1305 * at the cursor position, or the buffer selection will be replaced 1306 * if the selection is non-empty. 1307 * 1308 * Note: pasting is asynchronous, that is, we’ll ask for the paste data 1309 * and return, and at some point later after the main loop runs, the paste 1310 * data will be inserted. 1311 * 1312 * Params: 1313 * clipboard = the `GdkClipboard` to paste from 1314 * overrideLocation = location to insert pasted text 1315 * defaultEditable = whether the buffer is editable by default 1316 */ 1317 public void pasteClipboard(Clipboard clipboard, TextIter overrideLocation, bool defaultEditable) 1318 { 1319 gtk_text_buffer_paste_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct(), (overrideLocation is null) ? null : overrideLocation.getTextIterStruct(), defaultEditable); 1320 } 1321 1322 /** 1323 * This function moves the “insert” and “selection_bound” marks 1324 * simultaneously. 1325 * 1326 * If you move them to the same place in two steps with 1327 * [method@Gtk.TextBuffer.move_mark], you will temporarily select a 1328 * region in between their old and new locations, which can be pretty 1329 * inefficient since the temporarily-selected region will force stuff 1330 * to be recalculated. This function moves them as a unit, which can 1331 * be optimized. 1332 * 1333 * Params: 1334 * where = where to put the cursor 1335 */ 1336 public void placeCursor(TextIter where) 1337 { 1338 gtk_text_buffer_place_cursor(gtkTextBuffer, (where is null) ? null : where.getTextIterStruct()); 1339 } 1340 1341 /** 1342 * Redoes the next redoable action on the buffer, if there is one. 1343 */ 1344 public void redo() 1345 { 1346 gtk_text_buffer_redo(gtkTextBuffer); 1347 } 1348 1349 /** 1350 * Removes all tags in the range between @start and @end. 1351 * 1352 * Be careful with this function; it could remove tags added in code 1353 * unrelated to the code you’re currently writing. That is, using this 1354 * function is probably a bad idea if you have two or more unrelated 1355 * code sections that add tags. 1356 * 1357 * Params: 1358 * start = one bound of range to be untagged 1359 * end = other bound of range to be untagged 1360 */ 1361 public void removeAllTags(TextIter start, TextIter end) 1362 { 1363 gtk_text_buffer_remove_all_tags(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1364 } 1365 1366 /** 1367 * Removes a `GdkClipboard` added with 1368 * gtk_text_buffer_add_selection_clipboard(). 1369 * 1370 * Params: 1371 * clipboard = a `GdkClipboard` added to @buffer by 1372 * [method@Gtk.TextBuffer.add_selection_clipboard] 1373 */ 1374 public void removeSelectionClipboard(Clipboard clipboard) 1375 { 1376 gtk_text_buffer_remove_selection_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct()); 1377 } 1378 1379 /** 1380 * Emits the “remove-tag” signal. 1381 * 1382 * The default handler for the signal removes all occurrences 1383 * of @tag from the given range. @start and @end don’t have 1384 * to be in order. 1385 * 1386 * Params: 1387 * tag = a `GtkTextTag` 1388 * start = one bound of range to be untagged 1389 * end = other bound of range to be untagged 1390 */ 1391 public void removeTag(TextTag tag, TextIter start, TextIter end) 1392 { 1393 gtk_text_buffer_remove_tag(gtkTextBuffer, (tag is null) ? null : tag.getTextTagStruct(), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1394 } 1395 1396 /** 1397 * Emits the “remove-tag” signal. 1398 * 1399 * Calls [method@Gtk.TextTagTable.lookup] on the buffer’s 1400 * tag table to get a `GtkTextTag`, then calls 1401 * [method@Gtk.TextBuffer.remove_tag]. 1402 * 1403 * Params: 1404 * name = name of a `GtkTextTag` 1405 * start = one bound of range to be untagged 1406 * end = other bound of range to be untagged 1407 */ 1408 public void removeTagByName(string name, TextIter start, TextIter end) 1409 { 1410 gtk_text_buffer_remove_tag_by_name(gtkTextBuffer, Str.toStringz(name), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1411 } 1412 1413 /** 1414 * This function moves the “insert” and “selection_bound” marks 1415 * simultaneously. 1416 * 1417 * If you move them in two steps with 1418 * [method@Gtk.TextBuffer.move_mark], you will temporarily select a 1419 * region in between their old and new locations, which can be pretty 1420 * inefficient since the temporarily-selected region will force stuff 1421 * to be recalculated. This function moves them as a unit, which can 1422 * be optimized. 1423 * 1424 * Params: 1425 * ins = where to put the “insert” mark 1426 * bound = where to put the “selection_bound” mark 1427 */ 1428 public void selectRange(TextIter ins, TextIter bound) 1429 { 1430 gtk_text_buffer_select_range(gtkTextBuffer, (ins is null) ? null : ins.getTextIterStruct(), (bound is null) ? null : bound.getTextIterStruct()); 1431 } 1432 1433 /** 1434 * Sets whether or not to enable undoable actions in the text buffer. 1435 * 1436 * Undoable actions in this context are changes to the text content of 1437 * the buffer. Changes to tags and marks are not tracked. 1438 * 1439 * If enabled, the user will be able to undo the last number of actions 1440 * up to [method@Gtk.TextBuffer.get_max_undo_levels]. 1441 * 1442 * See [method@Gtk.TextBuffer.begin_irreversible_action] and 1443 * [method@Gtk.TextBuffer.end_irreversible_action] to create 1444 * changes to the buffer that cannot be undone. 1445 * 1446 * Params: 1447 * enableUndo = %TRUE to enable undo 1448 */ 1449 public void setEnableUndo(bool enableUndo) 1450 { 1451 gtk_text_buffer_set_enable_undo(gtkTextBuffer, enableUndo); 1452 } 1453 1454 /** 1455 * Sets the maximum number of undo levels to perform. 1456 * 1457 * If 0, unlimited undo actions may be performed. Note that this may 1458 * have a memory usage impact as it requires storing an additional 1459 * copy of the inserted or removed text within the text buffer. 1460 * 1461 * Params: 1462 * maxUndoLevels = the maximum number of undo actions to perform 1463 */ 1464 public void setMaxUndoLevels(uint maxUndoLevels) 1465 { 1466 gtk_text_buffer_set_max_undo_levels(gtkTextBuffer, maxUndoLevels); 1467 } 1468 1469 /** 1470 * Used to keep track of whether the buffer has been 1471 * modified since the last time it was saved. 1472 * 1473 * Whenever the buffer is saved to disk, call 1474 * `gtk_text_buffer_set_modified (@buffer, FALSE)`. 1475 * When the buffer is modified, it will automatically 1476 * toggled on the modified bit again. When the modified 1477 * bit flips, the buffer emits the 1478 * [signal@Gtk.TextBuffer::modified-changed] signal. 1479 * 1480 * Params: 1481 * setting = modification flag setting 1482 */ 1483 public void setModified(bool setting) 1484 { 1485 gtk_text_buffer_set_modified(gtkTextBuffer, setting); 1486 } 1487 1488 /** 1489 * Deletes current contents of @buffer, and inserts @text instead. 1490 * 1491 * If @len is -1, @text must be nul-terminated. 1492 * @text must be valid UTF-8. 1493 * 1494 * Params: 1495 * text = UTF-8 text to insert 1496 */ 1497 public void setText(string text) 1498 { 1499 gtk_text_buffer_set_text(gtkTextBuffer, Str.toStringz(text), cast(int)text.length); 1500 } 1501 1502 /** 1503 * Undoes the last undoable action on the buffer, if there is one. 1504 */ 1505 public void undo() 1506 { 1507 gtk_text_buffer_undo(gtkTextBuffer); 1508 } 1509 1510 /** 1511 * Emitted to apply a tag to a range of text in a `GtkTextBuffer`. 1512 * 1513 * Applying actually occurs in the default handler. 1514 * 1515 * Note that if your handler runs before the default handler 1516 * it must not invalidate the @start and @end iters (or has to 1517 * revalidate them). 1518 * 1519 * See also: 1520 * [method@Gtk.TextBuffer.apply_tag], 1521 * [method@Gtk.TextBuffer.insert_with_tags], 1522 * [method@Gtk.TextBuffer.insert_range]. 1523 * 1524 * Params: 1525 * tag = the applied tag 1526 * start = the start of the range the tag is applied to 1527 * end = the end of the range the tag is applied to 1528 */ 1529 gulong addOnApplyTag(void delegate(TextTag, TextIter, TextIter, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1530 { 1531 return Signals.connect(this, "apply-tag", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1532 } 1533 1534 /** 1535 * Emitted at the beginning of a single user-visible 1536 * operation on a `GtkTextBuffer`. 1537 * 1538 * See also: 1539 * [method@Gtk.TextBuffer.begin_user_action], 1540 * [method@Gtk.TextBuffer.insert_interactive], 1541 * [method@Gtk.TextBuffer.insert_range_interactive], 1542 * [method@Gtk.TextBuffer.delete_interactive], 1543 * [method@Gtk.TextBuffer.backspace], 1544 * [method@Gtk.TextBuffer.delete_selection]. 1545 */ 1546 gulong addOnBeginUserAction(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1547 { 1548 return Signals.connect(this, "begin-user-action", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1549 } 1550 1551 /** 1552 * Emitted when the content of a `GtkTextBuffer` has changed. 1553 */ 1554 gulong addOnChanged(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1555 { 1556 return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1557 } 1558 1559 /** 1560 * Emitted to delete a range from a `GtkTextBuffer`. 1561 * 1562 * Note that if your handler runs before the default handler 1563 * it must not invalidate the @start and @end iters (or has 1564 * to revalidate them). The default signal handler revalidates 1565 * the @start and @end iters to both point to the location 1566 * where text was deleted. Handlers which run after the default 1567 * handler (see g_signal_connect_after()) do not have access to 1568 * the deleted text. 1569 * 1570 * See also: [method@Gtk.TextBuffer.delete]. 1571 * 1572 * Params: 1573 * start = the start of the range to be deleted 1574 * end = the end of the range to be deleted 1575 */ 1576 gulong addOnDeleteRange(void delegate(TextIter, TextIter, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1577 { 1578 return Signals.connect(this, "delete-range", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1579 } 1580 1581 /** 1582 * Emitted at the end of a single user-visible 1583 * operation on the `GtkTextBuffer`. 1584 * 1585 * See also: 1586 * [method@Gtk.TextBuffer.end_user_action], 1587 * [method@Gtk.TextBuffer.insert_interactive], 1588 * [method@Gtk.TextBuffer.insert_range_interactive], 1589 * [method@Gtk.TextBuffer.delete_interactive], 1590 * [method@Gtk.TextBuffer.backspace], 1591 * [method@Gtk.TextBuffer.delete_selection], 1592 * [method@Gtk.TextBuffer.backspace]. 1593 */ 1594 gulong addOnEndUserAction(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1595 { 1596 return Signals.connect(this, "end-user-action", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1597 } 1598 1599 /** 1600 * Emitted to insert a `GtkTextChildAnchor` in a `GtkTextBuffer`. 1601 * 1602 * Insertion actually occurs in the default handler. 1603 * 1604 * Note that if your handler runs before the default handler 1605 * it must not invalidate the @location iter (or has to 1606 * revalidate it). The default signal handler revalidates 1607 * it to be placed after the inserted @anchor. 1608 * 1609 * See also: [method@Gtk.TextBuffer.insert_child_anchor]. 1610 * 1611 * Params: 1612 * location = position to insert @anchor in @textbuffer 1613 * anchor = the `GtkTextChildAnchor` to be inserted 1614 */ 1615 gulong addOnInsertChildAnchor(void delegate(TextIter, TextChildAnchor, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1616 { 1617 return Signals.connect(this, "insert-child-anchor", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1618 } 1619 1620 /** 1621 * Emitted to insert a `GdkPaintable` in a `GtkTextBuffer`. 1622 * 1623 * Insertion actually occurs in the default handler. 1624 * 1625 * Note that if your handler runs before the default handler 1626 * it must not invalidate the @location iter (or has to 1627 * revalidate it). The default signal handler revalidates 1628 * it to be placed after the inserted @paintable. 1629 * 1630 * See also: [method@Gtk.TextBuffer.insert_paintable]. 1631 * 1632 * Params: 1633 * location = position to insert @paintable in @textbuffer 1634 * paintable = the `GdkPaintable` to be inserted 1635 */ 1636 gulong addOnInsertPaintable(void delegate(TextIter, PaintableIF, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1637 { 1638 return Signals.connect(this, "insert-paintable", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1639 } 1640 1641 /** 1642 * Emitted to insert text in a `GtkTextBuffer`. 1643 * 1644 * Insertion actually occurs in the default handler. 1645 * 1646 * Note that if your handler runs before the default handler 1647 * it must not invalidate the @location iter (or has to 1648 * revalidate it). The default signal handler revalidates 1649 * it to point to the end of the inserted text. 1650 * 1651 * See also: [method@Gtk.TextBuffer.insert], 1652 * [method@Gtk.TextBuffer.insert_range]. 1653 * 1654 * Params: 1655 * location = position to insert @text in @textbuffer 1656 * text = the UTF-8 text to be inserted 1657 * len = length of the inserted text in bytes 1658 */ 1659 gulong addOnInsertText(void delegate(TextIter, string, int, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1660 { 1661 return Signals.connect(this, "insert-text", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1662 } 1663 1664 /** 1665 * Emitted as notification after a `GtkTextMark` is deleted. 1666 * 1667 * See also: [method@Gtk.TextBuffer.delete_mark]. 1668 * 1669 * Params: 1670 * mark = The mark that was deleted 1671 */ 1672 gulong addOnMarkDeleted(void delegate(TextMark, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1673 { 1674 return Signals.connect(this, "mark-deleted", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1675 } 1676 1677 /** 1678 * Emitted as notification after a `GtkTextMark` is set. 1679 * 1680 * See also: 1681 * [method@Gtk.TextBuffer.create_mark], 1682 * [method@Gtk.TextBuffer.move_mark]. 1683 * 1684 * Params: 1685 * location = The location of @mark in @textbuffer 1686 * mark = The mark that is set 1687 */ 1688 gulong addOnMarkSet(void delegate(TextIter, TextMark, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1689 { 1690 return Signals.connect(this, "mark-set", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1691 } 1692 1693 /** 1694 * Emitted when the modified bit of a `GtkTextBuffer` flips. 1695 * 1696 * See also: [method@Gtk.TextBuffer.set_modified]. 1697 */ 1698 gulong addOnModifiedChanged(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1699 { 1700 return Signals.connect(this, "modified-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1701 } 1702 1703 /** 1704 * Emitted after paste operation has been completed. 1705 * 1706 * This is useful to properly scroll the view to the end 1707 * of the pasted text. See [method@Gtk.TextBuffer.paste_clipboard] 1708 * for more details. 1709 * 1710 * Params: 1711 * clipboard = the `GdkClipboard` pasted from 1712 */ 1713 gulong addOnPasteDone(void delegate(Clipboard, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1714 { 1715 return Signals.connect(this, "paste-done", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1716 } 1717 1718 /** 1719 * Emitted when a request has been made to redo the 1720 * previously undone operation. 1721 */ 1722 gulong addOnRedo(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1723 { 1724 return Signals.connect(this, "redo", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1725 } 1726 1727 /** 1728 * Emitted to remove all occurrences of @tag from a range 1729 * of text in a `GtkTextBuffer`. 1730 * 1731 * Removal actually occurs in the default handler. 1732 * 1733 * Note that if your handler runs before the default handler 1734 * it must not invalidate the @start and @end iters (or has 1735 * to revalidate them). 1736 * 1737 * See also: [method@Gtk.TextBuffer.remove_tag]. 1738 * 1739 * Params: 1740 * tag = the tag to be removed 1741 * start = the start of the range the tag is removed from 1742 * end = the end of the range the tag is removed from 1743 */ 1744 gulong addOnRemoveTag(void delegate(TextTag, TextIter, TextIter, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1745 { 1746 return Signals.connect(this, "remove-tag", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1747 } 1748 1749 /** 1750 * Emitted when a request has been made to undo the 1751 * previous operation or set of operations that have 1752 * been grouped together. 1753 */ 1754 gulong addOnUndo(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1755 { 1756 return Signals.connect(this, "undo", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1757 } 1758 }